package Socket;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) {
        //创建socket
        try {
            ServerSocket socket = new ServerSocket(9999);
            System.out.println("服务端已开启，等待客户端发送数据。");
            //监听链接
            Socket s = socket.accept();
            //获取输入流
            InputStream in = s.getInputStream();
            //显示数据
            byte[] bys = new byte[1024];
            int len = in.read(bys);
            String str = new String(bys,0,len);
            System.out.println(str);
            //释放资源
            System.out.println("已接收客户端发送的数据，服务端关闭。");
            s.close();


        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
